/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.vale.dao;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.vale.entity.City;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Stateless
public class CityDAO extends AbstractFacade<City, Integer> {

    @PersistenceContext(unitName = "ValeEsperarPU")
    private EntityManager entityManager;

    public CityDAO() {
        super(City.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }

    public List<City> findByState(String idState) {
        Query query = entityManager.createQuery("SELECT c FROM City c WHERE c.idstate.idstate=:idstate ORDER BY c.cityname", City.class);
        query.setParameter("idstate", idState);
        List<City> l = query.getResultList();
        return (l != null ? l : new ArrayList<City>());
    }

}
